package com.keshan.service.impl;

import com.keshan.mapper.BloodOxygenMapper;
import com.keshan.pojo.BloodOxygen;
import com.keshan.pojo.BloodOxygenDayAvg;
import com.keshan.pojo.BloodOxygenExample;
import com.keshan.pojo.BloodOxygenHide;
import com.keshan.utils.DateUtil;
import com.keshan.service.BloodOxygenServices;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * @author keshan
 * @date 2022/10/21 - 15:54
 */
@Service
public class BloodOxygenServicesImpl implements BloodOxygenServices
{
    @Autowired
    BloodOxygenMapper bloodOxygenMapper;

    @Override
//    @Transactional  多个数据库同时查询，现在暂时还不需要，所以就暂时这个事务相关的就不写
    public int insertBySelectiveBloodOxygen(BloodOxygen bloodOxygen) {
        return bloodOxygenMapper.insertSelective(bloodOxygen);
    }

//    @Override
//    public List<BloodOxygen> getBloodOxygenListByImeiToday(String imei) {
//        BloodOxygenExample bloodOxygenExample = new BloodOxygenExample();
//        BloodOxygenExample.Criteria criteria = bloodOxygenExample.createCriteria();
//        criteria.andImeiEqualTo(imei);
//        List<Date> dateList = DateUtil.getStartAndEndToday();
//        criteria.andTimeBeginBetween(dateList.get(0),dateList.get(1));
//        List<BloodOxygen> bloodOxygenList = bloodOxygenMapper.selectByExample(bloodOxygenExample);
//        return bloodOxygenList;
//
//    }


//    @Override
//    public List<BloodOxygenHide> getBloodOxygenListHideByImei(String imei) {
//
//        BloodOxygenExample bloodOxygenExample = new BloodOxygenExample();
//        BloodOxygenExample.Criteria criteria = bloodOxygenExample.createCriteria();
//        criteria.andImeiEqualTo(imei);
//        return bloodOxygenMapper.selectHideByExample(bloodOxygenExample);
//    }


    @Override
    public List<BloodOxygenHide> getBloodOxygenListHideByUsernameToday(String username) {
        BloodOxygenExample bloodOxygenExample = new BloodOxygenExample();
        BloodOxygenExample.Criteria criteria = bloodOxygenExample.createCriteria();
        criteria.andUsernameEqualTo(username);
        List<Date> dateList = DateUtil.getStartAndEndToday();
        criteria.andTimeBeginBetween(dateList.get(0),dateList.get(1));
        return bloodOxygenMapper.selectHideByExample(bloodOxygenExample);
    }

    @Override
    public List<BloodOxygenDayAvg> getBloodOxygenListEverydayAvgMonth(String username) {
        List<Date> dateList = DateUtil.getStartAndEndTwoMonth();
        return bloodOxygenMapper.selectEverydayAvg(dateList.get(0),dateList.get(1),username);
    }

//    @Override
//    public List<BloodOxygen> getBloodOxygenListByImeiTodayAndMain(String imei) {
//        BloodOxygenExample bloodOxygenExample = new BloodOxygenExample();
//        BloodOxygenExample.Criteria criteria = bloodOxygenExample.createCriteria();
//        criteria.andImeiEqualTo(imei);
//        List<BloodOxygen> bloodOxygenList = bloodOxygenMapper.selectByExample(bloodOxygenExample);
//        List<BloodOxygen> bloodOxygens = new ArrayList<>();
//        Date date =new Date();
//        String datestr = new SimpleDateFormat("yyyyMMdd").format(date);
//        for (int i =0;i<bloodOxygenList.size();i++)
//        {
//            String strdate = bloodOxygenList.get(i).getTimeBeginStr().substring(0,8);
//            if (datestr.equals(strdate))
//            {
//                System.out.println(bloodOxygenList.get(i).toString());
//                bloodOxygens.add(bloodOxygenList.get(i));
//            }
//        }
//        return bloodOxygens;
//    }
}
